package main

/*
#include <stdbool.h>
#include <string.h>
typedef struct {
    int intVal;
    bool boolVal;
    char charArray[512];
} ParamInfo;
typedef struct {
    int intVal;
    bool boolVal;
    char charArray[512];
} ResultInfo;
*/
import "C"

import (
	"fmt"
	"unsafe"
)

//export calcResult
func calcResult(paramInfoPtr *C.ParamInfo, resultInfoPtr *C.ResultInfo) C.int {
	// Convert paramInfo to Go struct
	paramInfo := &ParamInfo{
		intVal:    int(paramInfoPtr.intVal),
		boolVal:   bool(paramInfoPtr.boolVal),
		charArray: C.GoString((*C.char)(unsafe.Pointer(&paramInfoPtr.charArray))),
	}
	fmt.Printf("go print:%v\n", paramInfo)
	// Call your Go function here with paramInfo and resultInfo
	resultInfo := yourFunction(paramInfo)

	// Convert resultInfo from Go struct to C struct
	resultInfoPtr.intVal = C.int(resultInfo.intVal)
	resultInfoPtr.boolVal = C.bool(resultInfo.boolVal)
	copy((*[512]byte)(unsafe.Pointer(&resultInfoPtr.charArray))[:], []byte(resultInfo.charArray))

	return C.int(0) // Return 0 or whatever error code you want to indicate success or failure
}

type ParamInfo struct {
	intVal    int
	boolVal   bool
	charArray string
}

type ResultInfo struct {
	intVal    int
	boolVal   bool
	charArray string
}

func yourFunction(paramInfo *ParamInfo) *ResultInfo {
	// Your logic goes here
	return &ResultInfo{
		intVal:    123,
		boolVal:   true,
		charArray: "Hello, Qt!",
	}
}

func main() {
	// Do nothing, just needed for `go build` to work
}
